package com.scs.application.modules.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.base.entity.Change;
import com.scs.application.modules.base.service.ChangeService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 基础属性变更表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/base/change")
public class ChangeController extends CrudController<ChangeService, Change>{
    //根据变更类型分组
    @GetMapping("/getChangeTypeList")
    public RestResult<List> getChangeTypeList() {
        QueryContext queryContext = QueryContextHolder.currentContext();
        Map<String, Object> mapParam = queryContext.getParams();
        QueryWrapper queryWrapper = Wrappers.<Change>query();
        queryWrapper.select("change_type as value,change_type as label");
        queryWrapper.groupBy("change_type");
        List<Map<String, Object>> list = service.listMaps(queryWrapper );
        return RestResult.ok("查询成功", list);
    }
}
